<template>
    <view>
      <!-- 轮播图 -->
      <!-- <swiper  
        style="height:180px"
        class="demo-swiper"
        previousMargin="10px"
        nextMargin="10px"
        indicator-dots
        autoplay
        circular
        :interval="3000" 
                >
        <view v-for="item in swipers" :key="item.id">
          <swiper-item  style="height:180px">
            <image style="height:180px" :src="item.image_src" mode="scaleToFill" />
          </swiper-item>
        </view>
      </swiper> -->
      <view>
        <img class="bg-img" src="http://zxjp-dzg-1301158478.cos.ap-shanghai.myqcloud.com/Image/2023-11-18/OIP%20%283%29.jpeg" alt="">
      </view>
    <view class="msg">
        欢迎来到这个可爱的小程序～
        <p style="margin-top: 20px;">不知道吃什么就选这里吧</p>
    </view>
    <view class="box">
        选到的菜是：
        <div class="turntable">
             {{ selectDish }}
        </div>
        <button class="btn" @click="startFn">开始</button>
        <button class="btn" @click="gameOver">stop</button>
    </view>

    </view>
  </template>
  
  <script>
  import { ref } from 'vue';

  export default {
    setup() {
        let timerId = ref('')
        let swipers = ref(
            [
                {
                    id: 1,
                    image_src: 'https://d-ssl.dtstatic.com/uploads/blog/202303/17/20230317005621_bb2f7.thumb.300_300_c.jpg_webp'
                },
                {
                    id: 2,
                    image_src: 'https://d-ssl.dtstatic.com/uploads/blog/202303/17/20230317005620_a7133.thumb.300_300_c.jpg_webp'
                },
                {
                    id: 1,
                    image_src: 'https://d-ssl.dtstatic.com/uploads/blog/202303/17/20230317005620_c0bff.thumb.300_300_c.jpg_webp'
                },
    
            ]
        )
        let luckarr = ref(['米线','米粉','黄焖鸡','黄焖排骨','烧烤','烤肉','日料','冷面','铁锅炖','麻辣烫','捡角（台湾菜）','牛排','麦当劳','肯德基','螺蛳粉','酸辣粉','新疆炒米粉','海底捞','潮汕火锅','牛肉拉面','猪脚饭','川菜','山西刀削面','麻辣拌','争鲜','金匠','冒菜'])
        let selectDish = ref('--')
         // 点击指针
        const startFn =() =>{
            console.log(11);
            timerId.value = setInterval(function(){

                let random=parseInt(Math.random()*luckarr.value.length)

                console.log('luckarr[random]',luckarr.value, random, luckarr.value[random]);
                selectDish.value = luckarr.value[random]

            }, 100)
        }
          // 游戏结束
        const gameOver = () => {
            console.log(timerId.value, '---------');
            clearInterval(timerId.value)
            }
        return {startFn, swipers, luckarr, selectDish, gameOver}
    }
   
  }
  </script>
  
  <style lang="scss" scoped>
  .search-box {
    // 设置定位效果为“吸顶”
    position: sticky;
    // 吸顶的“位置”
    top: 0;
    // 提高层级，防止被轮播图覆盖
    z-index: 999;
  }

  .bg-img {
    width: 100%;
    height: 40vh;
  }

  .box {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    height: 40vh;
  }
  .turntable {
    width: 70vw;
    height: 50px;
    line-height: 50px;
    text-align: center;
    border: 1px solid #000;
    border-radius: 5%;
    font-size: 30px;
  }

  .msg {
    padding-top: 30px;
    background-color: #fff;
    color: pink;
    font-weight: 700;
    height: 100px;
    // line-height:120px;
    text-align: center;
  }
  
  swiper {
    height: 400rpx;
  
    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }
  
  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15px 0;
  
    .nav-img {
      width: 128rpx;
      height: 140rpx;
    }
  }
  
  .floor-title {
    height: 60rpx;
    width: 100%;
    display: flex;
  }
  
  .right-img-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }
  
  .floor-img-box {
    display: flex;
    padding-left: 10rpx;
  }

  .btn {
    width: 275px;
    height: 50px;
    background: #000;
    color: pink;
  }
  </style>
  